import { createSlice, type Slice } from "@reduxjs/toolkit";
// import dayjs from "dayjs";
import type { ReceptionSlice } from "../type/ReceptionSlice";

const receptionSlice: Slice<ReceptionSlice> = createSlice({
  name: 'reception',
  initialState: {
    baseInfo: {
      producer: {
        name: '',
        groupName: ''
      },
      applicant: {
        name: '',
        groupName: ''
      },
      businessEntity: '',
      costCenter: '',
      budgetNumber: ''
    },
    receptionInfo: localStorage.receptionInfo ? JSON.parse(localStorage.receptionInfo) : {
      address: [] as string[],
      time: {
        start: undefined as undefined | number,
        end: undefined as undefined | number,
      },
      type: '',
      company: '',
      numberOfPeople: undefined as undefined | number,
      objective: '',
      entourage: '',
      visitingVehicles: []
    },
    step: 0
  },
  reducers: {
    setBaseInfo (state, action) {
      state.baseInfo = action.payload
    },
    setReceptionInfo (state, action) {
      state.receptionInfo = action.payload
      localStorage.receptionInfo = JSON.stringify(action.payload)
    },
    setStep (state, action) {
      state.step = action.payload
    }
  }
})

export const { setBaseInfo, setReceptionInfo, setStep } = receptionSlice.actions

export default receptionSlice
